package cn.lili.modules.email.config;

import cn.hutool.extra.mail.MailAccount;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 邮箱配置
 *
 * @author moxingjian
 * @version 1.0
 * @date 2023-10-20 15:59
 * <p>
 * 版本更新：
 * 更新版本号    更新人      更新时间      更新内容
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "email")
public class EmailConfig {

    /** 地址 **/
    private String host;

    /** 邮件 **/
    private String username;

    /** 授权码 **/
    private String password;

    /** 端口 **/
    private Integer port;

    /**
     * 初始化邮箱账户
     *
     * @return 邮箱账户
     */
    @Bean
    public MailAccount getMailAccount() {
        MailAccount account = new MailAccount();
        account.setHost(getHost());
        account.setPort(465);
        account.setAuth(Boolean.TRUE);
        account.setFrom(username);
        account.setUser(username);
        account.setPass(password);
        account.setSslEnable(Boolean.TRUE);
        return account;
    }
}
